#pragma once
#include <pthread.h>
#include <cassert>
class Mutex
{
public:
    Mutex(pthread_mutex_t& mutex)
        :_mutex(mutex)
    {}
    void lock()
    {
        int n = pthread_mutex_lock(&_mutex);
        assert(0 == n);
    }
    void unlock()
    {
        int n = pthread_mutex_unlock(&_mutex);
        assert(0 == n);
    }
private:
    pthread_mutex_t& _mutex; 
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t& mutex)
        :_lock(mutex)
    {
        _lock.lock();
    }
    ~LockGuard()
    {
        _lock.unlock();
    }
private:
    Mutex _lock;
};